import React from 'react'

import axios from 'axios'

class Axios extends React.Component {
    constructor(props) {
        super(props);
        this.state = {  
            list: []
        };
    }

    getData = () => {
        var url = 'https://www.imooc.com/search/hotwords';
        axios.post(url)
            .then((response) => {
                console.log(response.data);
                console.log(Object.prototype.toString.call(response.data.data));
                
                this.setState({  
                    list: response.data.data
                })
            })
            .catch((error) => {
                console.log(error)
            })
    }

    render() {
        return (
            <div>
                <h2>Axios从服务端获取数据</h2>
                <button onClick={this.getData}>获取数据</button>
                <br/>
                <hr/>
                <ul>
                    {
                        this.state.list.map((value, key) => {
                            return <li key={key}>{value}</li>
                        })      
                    }
                </ul>
            </div>
        );
    }
}

export default Axios;